<html>
<head><meta charset="utf-8"><title>Implementing asm! support in cg_clif · project-inline-asm · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/index.html">project-inline-asm</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Implementing.20asm!.20support.20in.20cg_clif.html">Implementing asm! support in cg_clif</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="203417752"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Implementing%20asm%21%20support%20in%20cg_clif/near/203417752" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Implementing.20asm!.20support.20in.20cg_clif.html#203417752">(Jul 09 2020 at 17:50)</a>:</h4>
<p>Does anybody know of a crate that has already switched to the new <code>asm!</code> syntax? I want to try if I can use an external assembler for inline asm in cg_clif, but I need something to test it with.</p>



<a name="203417809"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Implementing%20asm%21%20support%20in%20cg_clif/near/203417809" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Implementing.20asm!.20support.20in.20cg_clif.html#203417809">(Jul 09 2020 at 17:50)</a>:</h4>
<p><a href="https://github.com/bjorn3/rustc_codegen_cranelift/pull/1062">https://github.com/bjorn3/rustc_codegen_cranelift/pull/1062</a> already implemented <code>global_asm!</code> on Linux.</p>



<a name="203418594"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Implementing%20asm%21%20support%20in%20cg_clif/near/203418594" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Implementing.20asm!.20support.20in.20cg_clif.html#203418594">(Jul 09 2020 at 17:57)</a>:</h4>
<p><a href="https://github.com/rust-console/gba">https://github.com/rust-console/gba</a><br>
it's only in the repo i haven't pushed a release to <a href="http://crates.io">crates.io</a>, but someone did the asm rework for me.</p>



<a name="203418767"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Implementing%20asm%21%20support%20in%20cg_clif/near/203418767" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Implementing.20asm!.20support.20in.20cg_clif.html#203418767">(Jul 09 2020 at 17:59)</a>:</h4>
<p>some of the embedded wg crates have also switched</p>



<a name="203421283"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Implementing%20asm%21%20support%20in%20cg_clif/near/203421283" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Implementing.20asm!.20support.20in.20cg_clif.html#203421283">(Jul 09 2020 at 18:22)</a>:</h4>
<p>hm, arm32 is not supported by Cranelift and AArch64 is not complete enough for cg_clif. I need an x86_64 crate to test it.</p>



<a name="203426248"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Implementing%20asm%21%20support%20in%20cg_clif/near/203426248" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Implementing.20asm!.20support.20in.20cg_clif.html#203426248">(Jul 09 2020 at 19:06)</a>:</h4>
<p><span class="user-mention" data-user-id="133247">@bjorn3</span> You can try the <code>asm!</code> test cases in <code>src/test/assembly/asm</code> for a start.</p>



<a name="203426283"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Implementing%20asm%21%20support%20in%20cg_clif/near/203426283" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Implementing.20asm!.20support.20in.20cg_clif.html#203426283">(Jul 09 2020 at 19:06)</a>:</h4>
<p>Good idea!</p>



<a name="203430413"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Implementing%20asm%21%20support%20in%20cg_clif/near/203430413" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Implementing.20asm!.20support.20in.20cg_clif.html#203430413">(Jul 09 2020 at 19:42)</a>:</h4>
<p><span class="user-mention" data-user-id="143274">@Amanieu</span> How do I get from a <code>dx</code>  or <code>edx</code> to an <code>rdx</code> <code>InlineAsmReg</code>? <code>push</code> and <code>pop</code> require the full register width as operand.</p>



<a name="203447841"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Implementing%20asm%21%20support%20in%20cg_clif/near/203447841" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Implementing.20asm!.20support.20in.20cg_clif.html#203447841">(Jul 09 2020 at 22:09)</a>:</h4>
<p><span class="user-mention" data-user-id="133247">@bjorn3</span> Hmm? It should always use the largest register size by default. You need to use modifiers to get the sub-register names.</p>



<a name="203448012"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Implementing%20asm%21%20support%20in%20cg_clif/near/203448012" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Implementing.20asm!.20support.20in.20cg_clif.html#203448012">(Jul 09 2020 at 22:11)</a>:</h4>
<p>You can use the <code>emit</code> function on <code>InlineAsmReg</code> to generate the correct register name for inserting into the placeholder after you've allocated registers.</p>



<a name="203448189"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Implementing%20asm%21%20support%20in%20cg_clif/near/203448189" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Implementing.20asm!.20support.20in.20cg_clif.html#203448189">(Jul 09 2020 at 22:12)</a>:</h4>
<p>Use the <code>allocatable_registers</code> function to get a map of all registers in each register class, for register allocation where you turn register classes into physical registers.</p>



<a name="203448248"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Implementing%20asm%21%20support%20in%20cg_clif/near/203448248" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Implementing.20asm!.20support.20in.20cg_clif.html#203448248">(Jul 09 2020 at 22:13)</a>:</h4>
<p>I was using <code>reg.name()</code>. Can I leave the <code>modifier</code> of <code>emit</code> as <code>None</code>?</p>



<a name="203469450"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Implementing%20asm%21%20support%20in%20cg_clif/near/203469450" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Implementing.20asm!.20support.20in.20cg_clif.html#203469450">(Jul 10 2020 at 04:56)</a>:</h4>
<p>Sure, that should always produce the full register width</p>



<a name="203474380"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Implementing%20asm%21%20support%20in%20cg_clif/near/203474380" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Implementing.20asm!.20support.20in.20cg_clif.html#203474380">(Jul 10 2020 at 06:49)</a>:</h4>
<p>Thanks!</p>



<a name="203483348"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Implementing%20asm%21%20support%20in%20cg_clif/near/203483348" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Implementing.20asm!.20support.20in.20cg_clif.html#203483348">(Jul 10 2020 at 08:49)</a>:</h4>
<p><span class="user-mention" data-user-id="143274">@Amanieu</span> For <code>al</code> it still gives <code>al</code> as output. For <code>dx</code> it gives <code>rdx</code> as necessary.</p>



<a name="203483378"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Implementing%20asm%21%20support%20in%20cg_clif/near/203483378" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Implementing.20asm!.20support.20in.20cg_clif.html#203483378">(Jul 10 2020 at 08:49)</a>:</h4>
<p>That's because <code>al</code> is a <code>reg_byte</code> while <code>ax</code> is a <code>reg</code></p>



<a name="203483391"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Implementing%20asm%21%20support%20in%20cg_clif/near/203483391" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Implementing.20asm!.20support.20in.20cg_clif.html#203483391">(Jul 10 2020 at 08:49)</a>:</h4>
<p>They are treated as separate registers</p>



<a name="203483491"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Implementing%20asm%21%20support%20in%20cg_clif/near/203483491" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Implementing.20asm!.20support.20in.20cg_clif.html#203483491">(Jul 10 2020 at 08:50)</a>:</h4>
<p>Refer to <code>src/librustc_target/asm/x86.rs</code> for the exact list of all supported registers and register classes.</p>



<a name="203483528"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Implementing%20asm%21%20support%20in%20cg_clif/near/203483528" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Implementing.20asm!.20support.20in.20cg_clif.html#203483528">(Jul 10 2020 at 08:51)</a>:</h4>
<p>Is there a way to get the register size instead? Or Do I need to match on the reg class for that? Then I could use <code>mov</code> to and from a designated spill area instead.</p>



<a name="203483618"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Implementing%20asm%21%20support%20in%20cg_clif/near/203483618" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Implementing.20asm!.20support.20in.20cg_clif.html#203483618">(Jul 10 2020 at 08:52)</a>:</h4>
<p>No we don't have the register size. Maybe you could infer it from <code>supported_types</code>, but even that's a bit tricky.</p>



<a name="203483634"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Implementing%20asm%21%20support%20in%20cg_clif/near/203483634" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Implementing.20asm!.20support.20in.20cg_clif.html#203483634">(Jul 10 2020 at 08:52)</a>:</h4>
<p>I will match on the reg class then.</p>



<a name="203483667"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Implementing%20asm%21%20support%20in%20cg_clif/near/203483667" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Implementing.20asm!.20support.20in.20cg_clif.html#203483667">(Jul 10 2020 at 08:53)</a>:</h4>
<p>If you want some early feedback I'm happy to have a look at your code as it is right now to see if you're going in the right direction.</p>



<a name="203483817"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Implementing%20asm%21%20support%20in%20cg_clif/near/203483817" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Implementing.20asm!.20support.20in.20cg_clif.html#203483817">(Jul 10 2020 at 08:55)</a>:</h4>
<p>I am first working on saving and restoring clobbered register.</p>



<a name="203485915"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Implementing%20asm%21%20support%20in%20cg_clif/near/203485915" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Implementing.20asm!.20support.20in.20cg_clif.html#203485915">(Jul 10 2020 at 09:20)</a>:</h4>
<p>This is what I currently have: <a href="https://gist.github.com/bjorn3/d5fade6bff8400c0948fd7d8c2bbc213">https://gist.github.com/bjorn3/d5fade6bff8400c0948fd7d8c2bbc213</a></p>



<a name="203487596"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Implementing%20asm%21%20support%20in%20cg_clif/near/203487596" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Implementing.20asm!.20support.20in.20cg_clif.html#203487596">(Jul 10 2020 at 09:41)</a>:</h4>
<p>codegen_ssa does some additional lowering to InlineAsmOperandRef which you probably want. In particular it will lower Const to a string so it can be easily inserted into the asm.</p>



<a name="203487958"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Implementing%20asm%21%20support%20in%20cg_clif/near/203487958" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Implementing.20asm!.20support.20in.20cg_clif.html#203487958">(Jul 10 2020 at 09:44)</a>:</h4>
<p>Ok, will do that later</p>



<a name="203488175"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Implementing%20asm%21%20support%20in%20cg_clif/near/203488175" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Implementing.20asm!.20support.20in.20cg_clif.html#203488175">(Jul 10 2020 at 09:47)</a>:</h4>
<p>Also make sure you properly handle the case where rax is clobbered.</p>



<a name="203489072"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Implementing%20asm%21%20support%20in%20cg_clif/near/203489072" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Implementing.20asm!.20support.20in.20cg_clif.html#203489072">(Jul 10 2020 at 09:58)</a>:</h4>
<p>My suggestion would be to mov rbp, rax at the start of the function and then just use rbp everywhere. This is safe since rbp can't be used as an operand for inline asm.</p>



<a name="203494441"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Implementing%20asm%21%20support%20in%20cg_clif/near/203494441" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Implementing.20asm!.20support.20in.20cg_clif.html#203494441">(Jul 10 2020 at 11:10)</a>:</h4>
<p>I got something: <a href="https://gist.github.com/bjorn3/f88891324a14e9941544e822a71d8552">https://gist.github.com/bjorn3/f88891324a14e9941544e822a71d8552</a> It crashes though as <code>rdi</code> ends up with a value of 1 instead of <code>edx</code>.</p>



<a name="203495289"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Implementing%20asm%21%20support%20in%20cg_clif/near/203495289" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Implementing.20asm!.20support.20in.20cg_clif.html#203495289">(Jul 10 2020 at 11:24)</a>:</h4>
<p><span class="user-mention" data-user-id="133247">@bjorn3</span>  mov %rdi,%rbp uses AT&amp;T syntax, so it has the operands in the wrong order.</p>



<a name="203495767"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Implementing%20asm%21%20support%20in%20cg_clif/near/203495767" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Implementing.20asm!.20support.20in.20cg_clif.html#203495767">(Jul 10 2020 at 11:31)</a>:</h4>
<p>Oops, fixed.</p>



<a name="203495953"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Implementing%20asm%21%20support%20in%20cg_clif/near/203495953" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Implementing.20asm!.20support.20in.20cg_clif.html#203495953">(Jul 10 2020 at 11:33)</a>:</h4>
<p><span class="user-mention" data-user-id="133247">@bjorn3</span> Also you might be missing a <code>ret</code> instruction.</p>



<a name="203496061"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Implementing%20asm%21%20support%20in%20cg_clif/near/203496061" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Implementing.20asm!.20support.20in.20cg_clif.html#203496061">(Jul 10 2020 at 11:35)</a>:</h4>
<p>Why are you using a slot to save clobbered registers? Just use <code>push</code>/<code>pop</code>.</p>



<a name="203496163"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Implementing%20asm%21%20support%20in%20cg_clif/near/203496163" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Implementing.20asm!.20support.20in.20cg_clif.html#203496163">(Jul 10 2020 at 11:36)</a>:</h4>
<p>Yes, that fixed all benches for <a href="https://github.com/rust-lang/compiler-builtins/issues/365">rust-lang/compiler-builtins#365</a> when using an explicit register instead of a reg class.</p>



<a name="203496224"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Implementing%20asm%21%20support%20in%20cg_clif/near/203496224" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Implementing.20asm!.20support.20in.20cg_clif.html#203496224">(Jul 10 2020 at 11:37)</a>:</h4>
<p><span class="user-mention silent" data-user-id="143274">Amanieu</span> <a href="#narrow/stream/216763-project-inline-asm/topic/Implementing.20asm!.20support.20in.20cg_clif/near/203496061">said</a>:</p>
<blockquote>
<p>Why are you using a slot to save clobbered registers? Just use <code>push</code>/<code>pop</code>.</p>
</blockquote>
<p>Because <code>push</code> and <code>pop</code> only work for pointer sized registers. For <code>reg_byte</code> registers I can't get the register name for the full pointer sized register.</p>



<a name="203502175"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Implementing%20asm%21%20support%20in%20cg_clif/near/203502175" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Implementing.20asm!.20support.20in.20cg_clif.html#203502175">(Jul 10 2020 at 12:48)</a>:</h4>
<p><span class="user-mention" data-user-id="143274">@Amanieu</span> Do you mind doing a quick review of <a href="https://github.com/bjorn3/rustc_codegen_cranelift/issues/1064">bjorn3/rustc_codegen_cranelift#1064</a>?</p>



<a name="203503421"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Implementing%20asm%21%20support%20in%20cg_clif/near/203503421" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Implementing.20asm!.20support.20in.20cg_clif.html#203503421">(Jul 10 2020 at 13:02)</a>:</h4>
<p>Hmm I'm thinking we probably want to change <code>emit</code> to just return a <code>String</code>.</p>



<a name="203503617"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Implementing%20asm%21%20support%20in%20cg_clif/near/203503617" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Implementing.20asm!.20support.20in.20cg_clif.html#203503617">(Jul 10 2020 at 13:04)</a>:</h4>
<p>Yeah, that would be nicer. Any potential slowdown would be very small, as inline asm is (relatively) rare in comparison to other statements and terminators.</p>



<a name="203504220"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Implementing%20asm%21%20support%20in%20cg_clif/near/203504220" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Implementing.20asm!.20support.20in.20cg_clif.html#203504220">(Jul 10 2020 at 13:10)</a>:</h4>
<p>Do you want to review some more, or can I merge it?</p>



<a name="203504233"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Implementing%20asm%21%20support%20in%20cg_clif/near/203504233" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Implementing.20asm!.20support.20in.20cg_clif.html#203504233">(Jul 10 2020 at 13:10)</a>:</h4>
<p>I'm writing up some comments in the PR.</p>



<a name="203555882"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Implementing%20asm%21%20support%20in%20cg_clif/near/203555882" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Implementing.20asm!.20support.20in.20cg_clif.html#203555882">(Jul 10 2020 at 20:44)</a>:</h4>
<p>Thanks for the review <span class="user-mention" data-user-id="143274">@Amanieu</span>!</p>



<a name="203580989"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Implementing%20asm%21%20support%20in%20cg_clif/near/203580989" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Implementing.20asm!.20support.20in.20cg_clif.html#203580989">(Jul 11 2020 at 04:58)</a>:</h4>
<p><span class="user-mention silent" data-user-id="133247">bjorn3</span> <a href="#narrow/stream/216763-project-inline-asm/topic/Implementing.20asm!.20support.20in.20cg_clif/near/203496224">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="143274">Amanieu</span> <a href="#narrow/stream/216763-project-inline-asm/topic/Implementing.20asm!.20support.20in.20cg_clif/near/203496061">said</a>:</p>
<blockquote>
<p>Why are you using a slot to save clobbered registers? Just use <code>push</code>/<code>pop</code>.</p>
</blockquote>
<p>Because <code>push</code> and <code>pop</code> only work for pointer sized registers. For <code>reg_byte</code> registers I can't get the register name for the full pointer sized register.</p>
</blockquote>
<p>I think it'd make sense to have some internal mapping that lets you get from the <code>reg_byte</code> register to the full-sized containing register to be saved/loaded.</p>



<a name="203581013"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Implementing%20asm%21%20support%20in%20cg_clif/near/203581013" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Implementing.20asm!.20support.20in.20cg_clif.html#203581013">(Jul 11 2020 at 04:59)</a>:</h4>
<p><span class="user-mention" data-user-id="133247">@bjorn3</span> I'm curious about something: is the goal that cranelift will <em>never</em> have support for generating fixed blocks of assembly with defined inputs/outputs/clobbers, or just that it won't happen <em>soon</em> so doing external assembly will be a faster solution?</p>



<a name="203581059"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Implementing%20asm%21%20support%20in%20cg_clif/near/203581059" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Implementing.20asm!.20support.20in.20cg_clif.html#203581059">(Jul 11 2020 at 05:00)</a>:</h4>
<p>(Because quite orthogonally to <code>asm!</code>, I'd like to be able to provide raw target assembly when using cranelift as a code generator for other purposes.)</p>



<a name="203583308"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Implementing%20asm%21%20support%20in%20cg_clif/near/203583308" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Implementing.20asm!.20support.20in.20cg_clif.html#203583308">(Jul 11 2020 at 06:22)</a>:</h4>
<p>Cranelift will likely never have inline assembly support compatible with gcc/LLVM. Implementing it including every single detail/bug is a massive task: <a href="https://github.com/bytecodealliance/wasmtime/issues/1041#issuecomment-531574394">https://github.com/bytecodealliance/wasmtime/issues/1041#issuecomment-531574394</a></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>